package com.ymatou.iapi.godmch.testcase;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.deleteAgentConditionMarkupConfigBean;
import com.ymatou.iapi.godmch.parameter.setAgentConditionMarkupConfigBean;
import com.ymatou.iapi.godmch.service.deleteAgentConditionMarkupConfigCall;
import com.ymatou.iapi.godmch.service.setAgentConditionMarkupConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.markup_config_agent_price;
import com.ymttest.database.model.godmch.markup_config_agent_priceExample;
import com.ymttest.database.sqlwapper.godmch.markup_config_agent_priceWapper;
/**
*删除代理价按条件加价规则
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_deleteAgentConditionMarkupConfig{
	private static deleteAgentConditionMarkupConfigBean bean;
	private static deleteAgentConditionMarkupConfigCall call;
	markup_config_agent_priceWapper priceWapper=new markup_config_agent_priceWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除代理价按条件加价规则");
	}

	@Before
	public void caseUp() {
		bean=new deleteAgentConditionMarkupConfigBean();
		call=new deleteAgentConditionMarkupConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_deleteAgentConditionMarkupConfig_001() {
		Logger.start(true,"删除代理价按条件加价规则-商户代理类型存在的-返回成功");
		try {
			setAgentConditionMarkupConfigBean setAgentConditionMarkupConfigBean=GodmchManageCallService.initSetAgentConditionMarkupConfig();
			setAgentConditionMarkupConfigCall setAgentConditionMarkupConfigCall=GodmchManageCallService.setAgentConditionMarkupConfigCall(setAgentConditionMarkupConfigBean);
		
			markup_config_agent_priceExample priceExample=new markup_config_agent_priceExample();
			priceExample.createCriteria().andMch_idEqualTo(setAgentConditionMarkupConfigBean.getMchId());
			markup_config_agent_price agentPrice=priceWapper.selectByExample(priceExample).get(0);
			agentPrice.setUpdate_time(Date.from((LocalDateTime.now().plusDays(-1).atZone(ZoneId.systemDefault()).toInstant())));
			priceWapper.updateByPrimaryKey(agentPrice);
			bean.setMchId(setAgentConditionMarkupConfigBean.getMchId());
			bean.setMarkupId(agentPrice.getMarkup_id());
			call.setData(bean);
			call.callService();			
			
			agentPrice=priceWapper.selectByExample(priceExample).get(0);
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(-1, agentPrice.getConfig_status(), "验证Config_status");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_deleteAgentConditionMarkupConfig_002() {
		Logger.start(true,"删除代理价按条件加价规则-商户代理商户不存在-返回失败");
		try {
			setAgentConditionMarkupConfigBean setAgentConditionMarkupConfigBean=GodmchManageCallService.initSetAgentConditionMarkupConfig();
			setAgentConditionMarkupConfigCall setAgentConditionMarkupConfigCall=GodmchManageCallService.setAgentConditionMarkupConfigCall(setAgentConditionMarkupConfigBean);

			markup_config_agent_priceExample priceExample=new markup_config_agent_priceExample();
			priceExample.createCriteria().andMch_idEqualTo(setAgentConditionMarkupConfigBean.getMchId());
			markup_config_agent_price agentPrice=priceWapper.selectByExample(priceExample).get(0);
			agentPrice.setUpdate_time(Date.from((LocalDateTime.now().plusDays(-1).atZone(ZoneId.systemDefault()).toInstant())));
			priceWapper.updateByPrimaryKey(agentPrice);
			bean.setMchId(setAgentConditionMarkupConfigBean.getMchId()+11);
			bean.setMarkupId(agentPrice.getMarkup_id());
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("500", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_deleteAgentConditionMarkupConfig_003() {
		Logger.start(true,"删除代理价按条件加价规则-商户与代理类型关系不存在-返回失败");
		try {
			setAgentConditionMarkupConfigBean setAgentConditionMarkupConfigBean=GodmchManageCallService.initSetAgentConditionMarkupConfig();
			setAgentConditionMarkupConfigCall setAgentConditionMarkupConfigCall=GodmchManageCallService.setAgentConditionMarkupConfigCall(setAgentConditionMarkupConfigBean);
			
			markup_config_agent_priceExample priceExample=new markup_config_agent_priceExample();
			priceExample.createCriteria().andMch_idEqualTo(setAgentConditionMarkupConfigBean.getMchId());
			markup_config_agent_price agentPrice=priceWapper.selectByExample(priceExample).get(0);
			agentPrice.setUpdate_time(Date.from((LocalDateTime.now().plusDays(-1).atZone(ZoneId.systemDefault()).toInstant())));
			
			priceExample.clear();
			agentPrice=priceWapper.selectByExample(priceExample).get(0);
			
			priceWapper.updateByPrimaryKey(agentPrice);
			bean.setMchId(setAgentConditionMarkupConfigBean.getMchId());
			bean.setMarkupId(agentPrice.getMarkup_id());
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("500", call.getStatusCode1(), "验证status");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_deleteAgentConditionMarkupConfig_004() {
		Logger.start(true,"删除代理价按条件加价规则-mchId为空-返回失败");
		try {
			setAgentConditionMarkupConfigBean setAgentConditionMarkupConfigBean=GodmchManageCallService.initSetAgentConditionMarkupConfig();
			setAgentConditionMarkupConfigCall setAgentConditionMarkupConfigCall=GodmchManageCallService.setAgentConditionMarkupConfigCall(setAgentConditionMarkupConfigBean);
			
			markup_config_agent_priceExample priceExample=new markup_config_agent_priceExample();
			priceExample.createCriteria().andMch_idEqualTo(setAgentConditionMarkupConfigBean.getMchId());
			markup_config_agent_price agentPrice=priceWapper.selectByExample(priceExample).get(0);
			//bean.setMchId(setAgentConditionMarkupConfigBean.getMchId());
			bean.setMarkupId(agentPrice.getMarkup_id());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_deleteAgentConditionMarkupConfig_005() {
		Logger.start(true,"删除代理价按条件加价规则-markupId为空-返回失败");
		try {
			setAgentConditionMarkupConfigBean setAgentConditionMarkupConfigBean=GodmchManageCallService.initSetAgentConditionMarkupConfig();
			setAgentConditionMarkupConfigCall setAgentConditionMarkupConfigCall=GodmchManageCallService.setAgentConditionMarkupConfigCall(setAgentConditionMarkupConfigBean);

			bean.setMchId(setAgentConditionMarkupConfigBean.getMchId());
			//bean.setMarkupId(agentPrice.getMarkup_id());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}